package com.xcity.pomelo.response;

import java.util.ArrayList;
import java.util.List;

import com.xcity.db.entity.GuildApply;
import com.xcity.db.entity.Player;
import com.xcity.game.combat.CombatUtils;
import com.xcity.game.player.cache.PlayerCacheService;

import naga.x.App;
import naga.x.net.impl.pomelo.PomeloMessage;
import naga.x.net.impl.pomelo.protocol.Message;

@PomeloMessage(type = Message.Type.RESPONSE)
public class GetApplyListResponse extends Response{

	private List<ApplyPlayerInfo> list;
	
	public static class ApplyPlayerInfo{
		public long aid;
		public long pid;
		public String name;
		public int level;
		public int value;
		public ApplyPlayerInfo(Player player, GuildApply apply){
			this.aid = apply.getId();
			this.pid = apply.getApplicant();
			this.name = player.getName();
			this.level = player.getLevel();
			this.value = CombatUtils.calcCombatPower(player);
		}
	}
	
	public GetApplyListResponse(int serial, List<GuildApply> appliList) {
		super(serial);
		list = new ArrayList<ApplyPlayerInfo>();
		PlayerCacheService pcs = App.getApp().getServiceManager().get(PlayerCacheService.class);
		for(int i = 0, size = appliList.size(); i < size; i++){
			GuildApply apply = appliList.get(i);
			Player player = pcs.find(apply.getApplicant());
			if(player != null){
				list.add(new ApplyPlayerInfo(player, apply));
			}
		}
	}

	public List<ApplyPlayerInfo> getList() {
		return list;
	}

	public void setList(List<ApplyPlayerInfo> list) {
		this.list = list;
	}
	
}
